package com.hawthorn.redis.controller;

import com.hawthorn.entity.po.SysUserPO;
import com.hawthorn.redis.service.user.UserCacheService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>todo 系统用户缓存</p>
 * @author: andy.ten@tom.com | xukaixing@hotmail.com
 * @created: 2021/12/19 2:25 PM
 * @version v1.0.1
 * @copyright: Copyright (c)  andyten
 */
@Api(tags = {"redis-sysuser"})
@RestController
@RequestMapping("/user")
@Slf4j
public class UserCacheController
{
  @Autowired
  private UserCacheService userCacheService;

  /**
   * <p>todo 重新加载用户</p>
   * @author: andy.ten@tom.com
   * @date: 2021/12/20 8:39 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "加载->重新初始化用户", notes = "重新初始化用户")
  @ApiImplicitParams({
  })
  @GetMapping(value = "reloadUser")
  public void reloadUser()
  {
    userCacheService.init();
  }


  /**
   * <p>todo 根据用户账号新增用户</p>
   * @author: andy.ten@tom.com ｜ xukaixing@hotmail.com
   * @date: 2022/8/1 18:14
   * @version: 1.0.1
   */
  @ApiOperation(value = "新增 -> 根据用户账号新增用户", notes = "根据用户账号新增用户")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "sysUserPO", value = "sysUserPO", dataTypeClass = Object.class)
  })
  @PutMapping(value = "/saveUser")
  public void saveUser(@RequestBody SysUserPO sysUserPO)
  {
    userCacheService.saveUser(sysUserPO);
  }

  /**
   * <p>todo 根据po重新加载用户</p>
   * @author: andy.ten@tom.com ｜ xukaixing@hotmail.com
   * @date: 2022/8/1 14:55
   * @version: 1.0.1
   */
  @ApiOperation(value = "加载->根据po重新加载用户", notes = "根据po重新加载用户")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "sysUserPO", value = "sysUserPO", dataTypeClass = Object.class)
  })
  @PostMapping(value = "/updateUser")
  public void updateUser(@RequestBody SysUserPO sysUserPO)
  {
    userCacheService.updateUser(sysUserPO);
  }

  /**
   * <p>todo 根据用户账号重新加载用户</p>
   * @author: andy.ten@tom.com ｜ xukaixing@hotmail.com
   * @date: 2022/8/1 14:55
   * @version: 1.0.1
   */
  @ApiOperation(value = "加载->根据account重新加载用户", notes = "根据account重新加载用户")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "account", value = "account", dataTypeClass = String.class)
  })
  @PostMapping(value = "/updateUserByAccount")
  public void updateUserByAccount(@RequestParam String account)
  {
    userCacheService.updateUserByAccount(account);
  }
}
